package com.bj.disc.ui.login.vm

import androidx.lifecycle.MutableLiveData
import com.ai3d.rfid.base.vm.BaseViewModel
import com.ai3d.rfid.common.log.Logcat
import com.ai3d.rfid.common.proxy.ToastProxy
import com.ai3d.rfid.ext.request
import com.ai3d.rfid.network.proxy.NetworkProxy.accountApi
import com.bj.disc.ui.login.bean.RegisterReq
import com.bj.disc.util.DiscConstants
import com.bj.disc.ui.login.bean.SmsResp


class RegisterViewModel : BaseViewModel() {
    private val TAG = "RegisterViewModel"

    var account = MutableLiveData("")
    var verifyCode = MutableLiveData("")
    var password = MutableLiveData("")
    var firstName = MutableLiveData("")
    var secondName = MutableLiveData("")
    var isMame = MutableLiveData(true)
    var birthday = MutableLiveData(1900)
    var race = MutableLiveData(DiscConstants.REGISTER_RACE_MALAY)


    var isShowPwd = MutableLiveData(false)


    var verSmsResult = MutableLiveData<SmsResp>()
    var registerResult = MutableLiveData<String>()

    fun sendVerifyCode(userName: String) {
        request({ accountApi.sendVerifyCode(userName) }, {
            Logcat.d(TAG, "sendVerifyCode it : $it")
            verSmsResult.value = it
        }, {
            Logcat.d(TAG, "sendVerifyCode errorMsg : ${it.errorMsg}")
        })
    }


    fun register(registerReq: RegisterReq) {
        request({ accountApi.register(registerReq) }, {
            registerResult.value = it
        }, {
            ToastProxy.showShort(it.errorMsg)
            Logcat.d(TAG, "register errorMsg : ${it.errorMsg}")
        })
    }
}